<!--
 * @Description:
 * @Author: 猪脚饭
 * @Date: 2022-11-16 08:28:45
 * @LastEditors: 猪脚饭
 * @LastEditTime: 2022-11-17 18:06:26
-->

<template>
  <div class="agents-contains">
    <el-carousel :interval="4000" type="card" height="300px">
      <el-carousel-item v-for="item in imgList" :key="item.id">
        <img style="width: 100%; height: 100%;" :src="item.url" alt="pic">
      </el-carousel-item>
    </el-carousel>
    <div class="w">
      <div class="categoryShow" v-for="item in list" :key="item.id" @click="$router.push(`/property/''/''/${ item.id }`)">
        <div class="left">
          <img v-imgError :src="item.image" alt="">
        </div>
        <div class="right">
          <h1>{{ item.name }}</h1>
          <p>{{ item.desc }}</p>
        </div>
      </div>
      <!-- 分页器 -->
      <el-row type="flex" justify="center">
        <el-pagination style="margin-top: 20px;" :page-size="params._limit" layout="prev, pager, next" :total="total" @current-change="currentChange">
        </el-pagination>
      </el-row>
    </div>
    <FooterIndex />
  </div>
</template>

<script>
import { getAgentCount, getAgent } from '@/api/category'
export default {
  name: 'agentsIndex',
  data() {
    return {
      params: {
        _limit: 4, // 每页条数
        _start: 0 // 开始条数
      },
      list: [],
      total: 0,
      imgList: [
        { id: 1, url: require('@/assets/common/6.png') },
        { id: 2, url: require('@/assets/common/7.png') },
        { id: 3, url: require('@/assets/common/8.png') },
        { id: 4, url: require('@/assets/common/9.png') },
        { id: 5, url: require('@/assets/common/10.png') }
      ]
    }
  },
  activated() {
    // 只要组件被激活了，就重新初始化信息
    this.getAgent()
  },
  methods: {
    // 获取地产列表
    async getAgent() {
      this.list = await getAgent(this.params)
      this.total = await getAgentCount({})
    },
    // 分页
    currentChange(newPage) {
      this.params._start = (newPage - 1) * this.params._limit
      this.getAgent()
    }
  },
  beforeRouteLeave(to, from, next) {
    from.meta.top = window.scrollY
    next()
  }
}
</script>

<style lang="scss" scoped>
.agents-contains {
  height: 100%;
}
.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
.categoryShow {
  display: flex;
  height: 200px;
  margin-top: 15px;
  border: 1px solid #e5e4e7;
  padding: 10px 0px;
  .left {
    // background-color: pink;
    width: 30%;
    padding: 0px 70px;
    img {
      width: 230px;
      height: 180px;
    }
  }
  .right {
    // background-color: red;
    display: flex;
    flex-direction: column;
    width: 70%;
    font-size: 15px;
    border-left: 1px solid #e5e4e7;
    line-height: 40px;
    h1 {
      text-align: center;
    }
    p {
      text-indent: 2em;
      font-size: 18px;
    }
  }
}
.unFind {
  font-size: 30px;
}
</style>
